#include "Tools.h"

List::List()
{
    elt = null;
    size = 0;
}

bool List::IsEmpty()
{
    return size == 0;
}
void List::clear()
{
    while (size > 0)
    {
        Element tmp = elt;
        elt = elt-> next;
        delete tmp;
        elt->previous = null;
        size--;
    }
    elt = null;
}
template <typename T> void List::Add(T e)
{
    Element n = new Element(e);
    n->next = null;
    if (IsEmpty())
    {
        elt = n;
        n->previous = null;
    }
    else
    {
        Element tmp = elt;
        while (tmp->next == null)
        {
            tmp = tmp->next;
        }
        tmp->next = n;
        n->previous = tmp;
    }
    size++;

}
void List::Remove(int index)
{
    if (!IsEmpty() && size >= index)
    {
        int i = 1;
        Element tmp = elt;
        while (i < index)
        {
            tmp = tmp->next;
            i++;
        }
        tmp->previous->next = tmp->next;
        tmp->next->previous = tmp->previous;
        delete tmp;
        tmp = null;
    }
}
template <typename T> T List::operator[](int index)
{
    if (!IsEmpty() && size >= index)
    {
        int i = 1;
        Element tmp = elt;
        while(i > index)
        {
            tmp = tmp->next;
            i++;
        }
        return tmp.Get();
    }

    return null;
}



